package day1;

import java.util.ServiceLoader;

import eatapi.EatApi;
import transportapi.Transportation;
import workapi.Work;


public class Main {
    public static void main(String[] args) throws Exception {
        //获取work 服务
        ServiceLoader<Work> load = ServiceLoader.load(Work.class);
        Work work = load.findFirst().get();
        //调用
        work.work();
        //其他服务
        ServiceLoader<EatApi> eatLoader = ServiceLoader.load(EatApi.class);
        EatApi eatApi = eatLoader.findFirst().get();
        eatApi.eat();
        eatApi.drink();
        //反射获取
        Transportation transportation = getTransportation();
        transportation.transport();

    }
    private static Transportation getTransportation() throws Exception {
        Class<Transportation> transportationClass = (Class<Transportation>) Class.forName("transportservice.TransportationImpl");
        Transportation transportation = transportationClass.getDeclaredConstructor().newInstance();
        return transportation;
    }
}
